/*
 * @Author: wurangkun wurangkun@qq.com
 * @Date: 2023-04-04 15:23:40
 * @LastEditors: wurangkun wurangkun@qq.com
 * @LastEditTime: 2023-05-26 11:20:34
 * @FilePath: \myblog_server\src\index.ts
 * @Description: 引入中间件
 */
import * as Router from 'koa-router';
import bodyParser from 'koa-body';
// import {send} from "./utils/tools"
import { PORT } from './config';
import AppRoutes from './routes';
import "./utils/mkDir"
const Koa = require('koa')
const getParams = require('./middleware/getparams');

const app = new Koa();
const router = new Router();
// 添加全局方法 send
// app.context.send = send
//路由
AppRoutes.forEach(route => router[route.method](route.path, route.action));

// app.use(bodyParser());
app.use(bodyParser({
  multipart: true, // 支持文件上传
}));
// 自定义中间件函数
app.use(getParams());
app.use(router.routes());
app.use(router.allowedMethods());
app.listen(PORT);

console.log(`应用启动成功 端口:${PORT}`);
